package cc.mrbird.assets.service.impl;

import cc.mrbird.assets.dao.AssetTypeMapper;
import cc.mrbird.assets.domain.AssetType;
import cc.mrbird.assets.domain.Manufacturers;
import cc.mrbird.assets.service.AssetTypeService;
import cc.mrbird.assets.service.ManufacturersService;
import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.service.impl.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;
@Service("manufacturersService")
public class ManufacturersServiceImpl extends BaseService<Manufacturers> implements ManufacturersService {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public List<Manufacturers> findAllList(Manufacturers manufacturers, QueryRequest request) {
        try {
            Example example = new Example(Manufacturers.class);
            Example.Criteria criteria = example.createCriteria();
            example.setOrderByClause("manufacturers_id");
            return this.selectByExample(example);
        } catch (Exception e) {
            log.error("error", e);
            return new ArrayList<>();
        }
    }

    @Override
    public void add(Manufacturers manufacturers) {
        this.save(manufacturers);
    }

    @Override
    public Manufacturers findByName(String manufacturers_name) {
        Example example = new Example(Manufacturers.class);
        example.createCriteria().andCondition("lower(manufacturers_name)=", manufacturers_name.toLowerCase());
        List<Manufacturers> list = this.selectByExample(example);
        return list.isEmpty() ? null : list.get(0);
    }
}
